package com.yangzehan.mall.common;

import org.apache.commons.lang.StringUtils;

import java.util.*;

class ConcatSort {
    public ConcatSort() {
    }

    public String evaluate(String str, String sortIndex, String isDel, String desc) {
        List<String> list1 = Arrays.asList(str.split(";"));
        List<String> list = new ArrayList(list1);
        if (((String)list.get(0)).split(",").length != ((String)list.get(list.size() - 1)).split(",").length) {
            list.remove(list.size() - 1);
        }
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                Double str1=Double.valueOf(o1.split(",")[Integer.valueOf(sortIndex)-1]);
                Double str2=Double.valueOf(o2.split(",")[Integer.valueOf(sortIndex)-1]);
                return (int)(str1-str2);
            }
        });


        if (isDel != "1") {
            return StringUtils.join(list, ";");
        } else {
            ArrayList<String> new_list = new ArrayList();
            Iterator var8 = list.iterator();

            while(var8.hasNext()) {
                String jwd = (String)var8.next();
                ArrayList<String> temp_list = new ArrayList();

                for(int i = 0; i < jwd.split(",").length; ++i) {
                    if (i != Integer.valueOf(sortIndex) - 1) {
                        temp_list.add(jwd.split(",")[i]);
                    }
                }

                new_list.add(StringUtils.join(temp_list, ","));
            }

            return StringUtils.join(new_list, ";");
        }
    }

    public static void main(String[] args) {
        String s="4,106.3093948,29.6773472,133.600527001179;5,106.308812,29.677358,189.917138598017;1,106.31075,29.67746,0;2,106.310533,29.677362,23.6272458807684;3,106.309968,29.677356,78.2155101910354";
        System.out.println((new ConcatSort()).evaluate(s, "1", "1", "desc"));
    }
}



